<template>
    <el-dialog v-model="open" title="添加配送员" width="500">

        <el-form ref="ruleFormRef" :model="groupItem" :rules="rules" label-width="auto" status-icon>
            <el-form-item label="添加配送员" prop="name">
                <el-input v-model="groupItem.name" placeholder="请输入" />
            </el-form-item>
        </el-form>

        <!-- 弹窗右下角的按钮 -->
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="open = false">取消</el-button>
                <el-button>确认</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue';
import type { FormRules } from 'element-plus'
import api from '../../api';
import { ElMessage } from 'element-plus'
interface RuleForm {
    name: string
}
// let {open}=defineProps(["open"])









interface gro {
    _id: string,
    avatar: string,
    name: string,
    phone: string,
    // time: ''
}
let groupItem = ref<gro>({
    _id: '',
    avatar: '',
    name: '',
    phone: '',
    // time: ''
})
let open = ref(false)
let rules = reactive<FormRules<RuleForm>>({
    name: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },

    ],
})


const pageData = ref({
    currentPage: 1,
    pageSize: 11

})







const emit = defineEmits(['getGroupData']);


let handleok = () => {
    if (groupItem.value._id) {
        hand()
    } else {
        handleAdd();
    }
}




//新增

let handleAdd = async () => {
    let res = await api.couriers.add({
        name: groupItem.value.name
    })
    if (res.code == 200) {
        open.value = false;
        // getGroupData()
        // getGroupData()
        emit('getGroupData')
        ElMessage({
            message: '用户分组新增成功！',
            type: 'success',
        })
    } else {
        ElMessage.error('res.message')
    }
}


//修改
let hand = () => {

}















</script>

<style scoped></style>